#ifndef DATABASEOPERATE_H
#define DATABASEOPERATE_H

#include <QtDebug>
#include <QApplication>
#include <QtSql/QSqlDatabase>
#include <QMessageBox>
#include <QSqlQuery>
#include <QMap>

typedef QList<QString> TestAttr;
typedef QList<TestAttr> TestAttrList;
#ifndef TESTINF_
#define TESTINF_
struct TestInfo{
    QString num;
    QString open;
    QString close;
};
#endif

#ifndef CONDITION_
#define CONDITION_
struct Condition{
    QString band;
    QString date;
    QString shifts;
    QString suveyor;
    QString number;
};
#endif
class databaseOperate
{
public:
    static databaseOperate *Instance();
    explicit databaseOperate();
    ~databaseOperate();
    void opendb();
    void closedb();
    QSqlDatabase db;
    //查询样品
    void querySample(QMap<int, QString> &list);
    //查询样品属性信息
    void querySampleAttr(const int, QMap<int, QString> &list);
    //新增样品实例信息
    void addSample(QString, QMap<int, QString>);
    //新增样品属性信息
    void addSampleAttr(QMap<int, QString> tMap, int );
    //删除样品信息
    bool delSampleInfo(int);
    //编辑样品信息(修改)
    void editSampleInfo(QMap<int, QString>, int);

    //查询班次信息
    void queryShifts(QMap<int, QString> &list);
    //查询检验员信息
    void querySurveyor(QMap<int, QString> &list);

    //新增测试属性信息
    void addTestAttrInfo(QMap<int, QString> tMap, int);
    //查询测试信息
    void queryTestInstAttr(TestAttrList &c);
    //新增测试信息_new
    void addTestInfo(QList<TestInfo>, QString, QString, QString, QString, QString);
    void queryTestInfo(TestAttrList &list);
    void queryCondition(Condition cond, TestAttrList &list);
    //查询测试结果表中班次，检验员，牌号信息
    void queryTestShiftInfo(QList<QString> &list);
    void queryTestSurveyorInfo(QList<QString> &list);
    void queryTestSampleInfo(QList<QString> &list);
    //新增样品
    void addSample(QString);
    void addShifts(QString);
    void addSurveyor(QString);
    void deleteSample(int);
    void deleteShifts(int);
    void deleteSurveyor(int);
    //删除测试结果
    void deleteTestInfo(QList<int>);
public:
    void queryPortIni(QString &, int);
    void readIni();
private:
    static databaseOperate *self;   //数据库自身对象
    QString sqlValue = "";
};

#endif // DATABASEOPERATE_H
